package com.company.gxcpc2020;

import java.util.Scanner;

public class GxcpcC {
    public static int n;
    public static int m;
    public static int k;
    public static int[][] map;
    public static int[][] dp;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            n = sc.nextInt();
            m = sc.nextInt();
            k = sc.nextInt();
            map = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    map[i][j] = sc.nextInt();
                }
            }
            int num = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    dp = new int[n][m];
                    num += find(i, j);
                }
            }
            System.out.println(num);
        }
    }

    public static int find(int x, int y) {
        int num = 0;
        i:
        for (int i = x; i < n; i++) {
            boolean flag = true;
            for (int j = y; j < m; j++) {
                if (i == 0 && j == 0) {
                    dp[i][j] = map[i][j];
                } else {
                    int ts = i - 1 >= 0 ? dp[i - 1][j] : 0;
                    int ls = j - 1 >= 0 ? dp[i][j - 1] : 0;
                    int tls = i - 1 >= 0 && j - 1 >= 0 ? dp[i - 1][j - 1] : 0;
                    dp[i][j] = map[i][j] + ts + ls - tls;
                }
                if (dp[i][j] > k) {
                    num += j - y;
                    flag = false;
                    if (i == x) {
                        break i;
                    }
                    break;
                }
            }
            if (flag) {
                num += m - y;
            }
        }
        return num;
    }
}
